
import { password } from "../../../../js/modules/account.js";
import {profile} from"../../../../js/modules/store.js";
const info = require("../../../../js/modules/info.js");
import { forms, storage, util } from '../../../../js/util';
import authorize from '../../../../js/modules/authorize.js'

var app = getApp();
import BasePage from '../../../../js/common/base-page'
BasePage({
  pageKey:"findPayPwd",

  /**
   * 页面的初始数据
   */
  data: {
    pageType: 1, //1:登录页面  2:注册页面  3:找回密码
    step: 0,
    step1: "display:block;",
    step2: "display:none;",
    step3: "display:none;",
    title1: "on",
    title2: "",
    title3: "",
    example: {
      classNames: 'ec-animate--fadeIn',
      enter: true,
      exit: true,
      in: true
    },
    forms: {
      Mobile: {
        value: "18981772611",
        validate: "isnull|mobile",
        error: "请输入正确的手机号"
      },
      PicVerifyCode: {
        value: "",
        validate: "isnull",
        error: "请输入正确的校验码"
      },
      ValidateCode: {
        value: "",
        validate: "isnull",
        error: "请输入正确的短信校验码"
      },
      Password: {
        value: "",
        validate: "isnull|pwd",
        error: "请输入正确的密码"
      },
      RepPassword: {
        value: "",
        validate: "isnull|pwd",
        error: "请输入正确的确认密码"
      },
    },
    current: null,  
    notifyTime: 60,
    isSendSmsCode: false, //是否已发送短信校验码
    totleHeight: '603px'
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //判断是否登录
    if (!authorize.isLogin('store')) {
      authorize.redirect('store');
      return;
    }

    var that = this;

    //获得发送短信组件
    this.smsVerifyCode = this.selectComponent("#smsVerifyCode");
    //设置回调
    this.smsVerifyCode.data.callback = this.bindSmsVerifyCode;

    profile.get_initiator_mobile(function(content){
      that.setData({
        mobile_info:content
      })
    });
  },
  /**
   * 表单值绑定
   */
  bindFormValue: function (e) {
    e = e.detail;
    this.data.forms[e.target.id].value = e.detail.value;

  },
  /*
  发送短信验证码
   */
  bindSmsVerifyCode: function (callback) {
    var that = this;
    if (!this.step1_validate()) return;
    var mobile = this.data.mobile_info.Mobile;
    var dir = storage.get("LoginSessionVirtualDirKey")||'';
    var data = {
      mobile: mobile,
      proprietorId:app.dns.proprietorId,
      code:dir
    };

    info.sms.getSmsVerifyCode(data, "account.store.validatecode.get", function (content) {
      if (callback && typeof (callback) == "function") {
        callback(content);
      }
    });
  },
  step1_validate: function () {

    var mobile = this.data.mobile_info.Mobile;
    if (mobile == undefined || mobile.length == 0) {
      util.alert("手机号未验证成功");
      return false;
    }
    return true;
  },
  /**验证 */
  step1: function () {
    var that = this;
    if (!this.step1_validate()) return;
    var mobile = this.data.mobile_info.Mobile;
    var sms_code = this.data.forms.ValidateCode.value;
    info.sms.validate_sms("account.store.validatecode.validate",mobile, sms_code,
      function (res) {
          that.setData({
            step: 1,
            step1: "display:none;",
            step2: "display:block;",
            step3: "display:none;",
            title1: "on",
            title2: "on",
            title3: ""
          });
      
      });
  },
  /**重置密码 */
  step2: function (param) {
    var that = this;
    var mobile = this.data.mobileToken;
    if (!forms.validate(this.data.forms.Password)) return false;
    if (!forms.validate(this.data.forms.RepPassword)) return false;
    if (!forms.compare(this.data.forms.Password, this.data.forms.RepPassword)) return;

    password.find_pay_pwd("store",this.data.forms.Password.value,
      function (res) {
          that.setData({
            step: 2,
            step1: "display:none;",
            step2: "display:none;",
            step3: "display:block;",
            title1: "on",
            title2: "on",
            title3: "on"
          });

      });
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () { },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  onExited() {
    // console.log("exited")
    this.setData({
      pageType: this.data.pageIndex
    });
  }
});